package com.jack.thinking.java._22.swing.pane;

import java.awt.BorderLayout;

import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import com.utils.SwingConsole;

/**
 * 页签
 * @author wangbingwu
 *
 */
public class MyTabbedPane extends JFrame{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String[] flavors = {
		"Jack", "Jane", "Li", "Zhou", "Wang", "Ly"
	};
	
	private JTabbedPane tabs = new JTabbedPane();
	private JTextField txt = new JTextField(20);
	
	public MyTabbedPane() {
		int i = 0;
		for(String flavor : flavors) {
			tabs.addTab(flavor, new JButton("Tabbed pane " + i++));
		}
		
		tabs.addChangeListener(new ChangeListener() {

			@Override
			public void stateChanged(ChangeEvent e) {
				txt.setText("Tab selected: " + tabs.getSelectedIndex());
			}
			
		});
		
		add(BorderLayout.SOUTH, txt);
		add(tabs);
	}
	
	public static void main(String[] args) {
		SwingConsole.run(new MyTabbedPane(), 400, 250);
	}
}
